angular.module('demo', [])//模块名，注入到admin 主模块中

.config(function DemoRoutes($stateProvider) {
    $stateProvider
        .state('userList', {//路由名称
            parent: 'admin',
            url: '/userList?{user_name:string}',//url以及参数定义
            params: {
                page: { value: 1, squash: true },//初始化url中的参数，不需要可以不写
                size: { value: 10, squash: true }
            },
            views: {
                'main@admin': {
                    templateUrl: 'admin/demo/list.html',//html地址
                    controller: 'DemoController as vm',//控制器和他的别名
                    resolve: {
                        initialList: function(Demo, $stateParams) {//从后台预加载的数据,Demo-注入的service
                            return Demo.search({
                                user_name : $stateParams.user_name,
                                pageInfo: {
                                    pageSize: $stateParams.size,
                                    pageNumber: $stateParams.page
                                }
                            })
                        }
                    }
                }
            }
        })

        .state('userAdd',{
            url: '/userAdd',
            controller: 'DemoAddController as vm',//控制器和他的别名
            templateUrl: 'admin/demo/userAdd.html'
        })

        .state('userUpdate',{
            url: '/userUpdate?{id:int}&{user_name:string}',
            controller: 'DemoUpdateController as vm',//控制器和他的别名
            templateUrl: 'admin/demo/userUpdate.html'
        })

})

.service('Demo', DemoModel)//声明

.controller('DemoController', DemoController)
.controller('DemoAddController',DemoAddController)
.controller('DemoUpdateController',DemoUpdateController)
.controller('ModalInstanceCtrl', function ($scope, $uibModalInstance) {
    $scope.ok = function () {
        $uibModalInstance.close('ok');
    };

    $scope.cancel = function () {
        $uibModalInstance.close('cancel');
        //$uibModalInstance.dismiss('cancel');
    };
})

